package com.yngk.tuyou;

import java.util.Map;
import java.util.TreeMap;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class IntegerUserMapAdapter extends XmlAdapter<IntegerUserMap, Map<Integer, User>>{

	@Override
	public IntegerUserMap marshal(Map<Integer, User> arg0) throws Exception {
		
		System.out.println("-----------执行序列化-----------");
		IntegerUserMap map = new IntegerUserMap();
		for(Map.Entry<Integer, User> e : arg0.entrySet()){
			
			IntegerUserMap.IntegerUserEntry iue = new IntegerUserMap.IntegerUserEntry();
			iue.setUser(e.getValue());
			iue.setId(e.getKey());
			map.getEntries().add(iue);
		}
		return map;
	}

	@Override
	public Map<Integer, User> unmarshal(IntegerUserMap arg0) throws Exception {
		
		System.out.println("-----------执行反序列化-----------");
		Map<Integer, User> map = new TreeMap<Integer, User>();
		for(IntegerUserMap.IntegerUserEntry e : arg0.entries){
			
			map.put(e.getId(), e.getUser());
		}
		return map;
	}
}
